﻿using System;
using System.Text;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Mod_frm_StockCheckAffirmOrders : System.Web.UI.Page
{
    /// <summary>
    /// 页面加载事件
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();

        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            if (!IsPostBack)
            {
                ////////////////按钮权限控制 Begin /////////////////////////
                string strCurrPageID = this.Page.Request.Params["PageID"];
                this.ControlButtonVisible(strUserID, strCurrPageID);
                //////////////////////  End ///////////////////////////////

                this.GetStockCheckByMain(strUserID, 8);
            }
            else
            {
                this.lblJs.Text = "";//清空Js脚本
                this.labMessage.Text = "";
            }

            this.ibtnDelete0.Attributes.Add("onClick", "return confirm('您真的要作废所选的项吗？');");
            this.lbtnDelete0.Attributes.Add("onClick", "return confirm('您真的要作废所选的项吗？');");
            this.lbtnDelete1.Attributes.Add("onClick", "return confirm('彻底作废将无法恢复数据。您真的要作废所选的项吗？');");
        }
        else
        {
            ClsMenuDAL cls_Menu = new ClsMenuDAL();
            string strMessage = cls_Menu.GetSystemCode("1", "00", this.ctbAdd0.Text.Trim(), 4);//取消当前系统编码
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='../index.aspx'</script>";
        }
    }

    public void ChangPage(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        DataSet dst = cls_Property.SetOrGetCorporationDataSet;

        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            string strKey = ((LinkButton)sender).CommandName;
            int intPageIndex = this.dgrdResult.CurrentPageIndex;
            int intPageCounts = this.dgrdResult.PageCount;

            if (strKey == "0")
            {
                intPageIndex = 0;
            }
            else if (strKey == "1")
            {
                if (intPageIndex > 0) intPageIndex -= 1;
            }
            else if (strKey == "2")
            {
                if (intPageIndex < intPageCounts - 1) intPageIndex += 1;
            }
            else
            {
                intPageIndex = intPageCounts - 1;
            }

            this.BindStockCheckByDataView(dst, intPageIndex);
        }
    }

    /// <summary>
    /// 从表记录翻页
    /// </summary>
    public void ChildChangPage(object sender, EventArgs e)
    {
        //获取保存的从表中的结果集和DataGrid控件
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        DataSet dst = cls_Property.SetOrGetChildResultDataSet;
        DataGrid dgrd = cls_Property.SetOrGetChildDataGridControl;

        if (dst != null && dgrd != null)
        {
            string strKey = ((LinkButton)sender).CommandName;
            int intPageIndex = dgrd.CurrentPageIndex;
            int intPageCounts = dgrd.PageCount;

            if (strKey == "0")
            {
                intPageIndex = 0;
            }
            else if (strKey == "1")
            {
                if (intPageIndex > 0) intPageIndex -= 1;
            }
            else if (strKey == "2")
            {
                if (intPageIndex < intPageCounts - 1) intPageIndex += 1;
            }
            else
            {
                intPageIndex = intPageCounts - 1;
            }

            this.BindStockCheckChildByDataView(dgrd, dst, intPageIndex);
        }
    }

   /// <summary>
    /// 新增记录
    /// </summary>
    public void AddStockCheckInfo(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            ImageButton ibtnAdd = (ImageButton)sender;
            int intCommandName = Int32.Parse(ibtnAdd.CommandName);
            ClsStockOrdersAffirmDAL ClsStockOrdersDAL = new ClsStockOrdersAffirmDAL();

            if (intCommandName == 0)//打开主表添加面板
            {
                ClsMenuDAL cls_Menu = new ClsMenuDAL();

                string strCode = cls_Menu.GetSystemCode("0", "00", "", 64);//获取系统编码

                if (strCode != "Error")
                {
                    this.panAddResult.Visible = true;
                    this.ctbAdd0.Text = strCode;
                    this.ctsbChkValiDate.Text = System.DateTime.Today.ToShortDateString();
                    this.lblJs.Text = "<script>document.getElementById('" + this.ctsbAdd0.ClientID + "_txtBox').focus();</script>";
                }
                else
                {
                    this.lblJs.Text = "<script>alert('新增记录失败，请重试！')</script>";
                }
            }
            else if (intCommandName == 1)//关闭主表添加面板
            {
                this.panAddResult.Visible = false;
            }
            else if (intCommandName == 2)//保存主表添加记录
            {                
                //保存主表新增记录
                string strs_id = this.ctbAdd0.Text.Trim();//实盘单确认单号
                string strVa_date = this.ctsbChkValiDate.Text.ToString().Trim();//实盘单确认日期                
                string strTm_no = this.CuTextSelectBox2.Text.Trim();//实盘单号                
                string strWh_id = this.ctsbAddWh_id.Text.Trim();
                string strOper = strUserID;//录入人
                string strRemark = this.ctbAdd1.Text.Trim();//盘点原因             

                if (strVa_date.Length == 0)
                {
                    this.labMessage.Text = "<script language='javascript'>alert('实盘单确认日期不能为空！');</script>";
                }
                else if (strTm_no.Length == 0)
                {
                    this.labMessage.Text = "<script language='javascript'>alert('实盘单号不能为空！');</script>";
                }
                else
                {
                    DateTime strs_date = DateTime.Parse(strVa_date);//实盘单确认日期
                    DateTime strTm_date = DateTime.Parse(this.ctsbAdd0.Text.Trim());//实盘单日期

                    Boolean bolIsCussee = ClsStockOrdersDAL.AddCheckStock(strs_id, strs_date, strTm_no, strTm_date, strWh_id, strOper, strRemark);
                    if (bolIsCussee)
                    {                        
                        //重新绑定结果
                        this.GetStockCheckByMain(strUserID, cls_Property.SetOrGetDataSetType);

                        //主表新增后直接打开从表进行新增从表记录 Begin///////////////////////////     
                        this.panAddResult.Visible = false;
                        ImageButton ibtn = new ImageButton();
                        int intItems = this.dgrdResult.Items.Count - 1;

                        for (int i = intItems; i >= 0; i--)
                        {
                            string strRs_No = ((CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRs0")).Text.Trim();

                            if (strRs_No == strs_id)
                            {
                                ibtn = (ImageButton)this.dgrdResult.Items[i].FindControl("ibtnOpenChild");
                                break;
                            }
                        }

                        this.OpenChildResult(ibtn, null);
                        this.AddStockCheckInfo(this.ibtnAdd, null);
                        //主表新增后直接打开从表进行新增从表记录 End///////////////////////////
                    }
                    else
                    {
                        this.lblJs.Text = "<script>alert('新增记录失败，请重试！')</script>";
                    }
                }
            }
            else//***********************************对从表进行新增操作***********************************
            {
                int intIndex = Int32.Parse(this.ibtnAdd.CommandArgument);

                Panel panChildAddResult = (Panel)this.dgrdResult.Items[intIndex].FindControl("panChildAddResult");

                if (intCommandName == 3)//关闭从表添加面板
                {
                    panChildAddResult.Visible = false;
                }
                else if (intCommandName == 4)//保存从表添加记录
                {
                    //此处写保存从表新增记录的代码
                    DataGrid dgrd = new DataGrid();
                    string strDm_No = "";//主表单据号
                    int intChildCount = this.dgrdResult.Items.Count;

                    for (int i = 0; i < intChildCount; i++)
                    {
                        Panel panItem = (Panel)this.dgrdResult.Items[i].FindControl("panItem");

                        if (panItem.Visible)
                        {
                            strDm_No = ((CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRs0")).Text.Trim();//主表单据号
                            dgrd = (DataGrid)this.dgrdResult.Items[i].FindControl("dgrdChildResult");
                            break;
                        }
                    }
                    string strProductId = ((CuTextSelectBox)dgrdResult.Items[intIndex].FindControl("ctsbChildAddIm_no")).Text.Trim();//商品编号
                    string strBatchNo = ((CuTextBox)dgrdResult.Items[intIndex].FindControl("ctbChildAddBatchNo")).Text.Trim();//批号
                    string stroo_no = ((CuTextBox)dgrdResult.Items[intIndex].FindControl("CuTextBox1")).Text.Trim();//识别码
                    decimal dCheckQty = decimal.Parse(((TextBox)dgrdResult.Items[intIndex].FindControl("ctbChildAddCheckQty")).Text.Trim());////实盘数量
                    string strChildRemark = ((CuTextBox)dgrdResult.Items[intIndex].FindControl("ctbChildAddRemark")).Text.Trim();//备注

                    CuTextBox ctsbStoreQty = (CuTextBox)dgrdResult.Items[intIndex].FindControl("ctbChildAddStoreQty");//库存数量

                    Boolean bolIsCussee = ClsStockOrdersDAL.AddChildCheckStock(strDm_No, strProductId, strBatchNo, stroo_no, decimal.Parse(ctsbStoreQty.Text.Trim()), dCheckQty, strChildRemark);

                    if (!bolIsCussee)
                    {
                        this.lblJs.Text = "<script>alert('不能新增相同的商品，请重试！')</script>";
                    }
                    else
                    {
                        ctsbStoreQty.Text = "";
                    }

                    //新增后重新绑定明细表
                    DataSet dst = ClsStockOrdersDAL.GetStockCheckChilds(strDm_No);

                    if (dst != null && dst.Tables[0].Rows.Count > 0)
                    {
                        this.BindStockCheckChildByDataView(dgrd, dst, 0);
                    }

                    ((ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnOpenChild")).Attributes.Remove("OnClick");

                }
                else if (intCommandName == 5)//打开从表添加面板
                {
                    panChildAddResult.Visible = false;

                    CuTextSelectBox ctsbChildAdd0 = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbChildAdd0");
                    //this.lblJs.Text = "<script>document.getElementById('dgrdResult_ctl03_ctsbChildAddIm_no_txtBox').focus();</script>";
                    //this.lblJs.Text = "<script>document.getElementById('" + ctsbChildAddIm_no.ClientID + "_txtBox').focus();</script>";
                }
            }
        }
        else
        { 
        
        }
    } 

    /// <summary>
    /// 修改记录
    /// </summary>
    public void UpDateStockCheckInfo(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        ClsStockOrdersAffirmDAL cls_CheckManageDAL = new ClsStockOrdersAffirmDAL();
        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            ImageButton ibtnUpdate = (ImageButton)sender;
            int intCommandName = Int32.Parse(ibtnUpdate.CommandName);
            int intIndex = Int32.Parse(ibtnUpdate.CommandArgument);

            if (intCommandName == 0)//主表确认
            {
                int intCount = this.dgrdResult.Items.Count;

                for (int i = 0; i < intCount; i++)
                {
                    bool IsChecked = ((CheckBox)this.dgrdResult.Items[i].FindControl("chkRsSelect")).Checked;
                    
                    if (IsChecked)
                    {
                        string strTm_No = ((CuTextSelectBox)this.dgrdResult.Items[i].FindControl("CuTextSelectBox4")).Text.Trim();
                        string strs_id = ((CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRs0")).Text.Trim();//实盘确认单号

                        string strReturn = cls_CheckManageDAL.CheckWhetherAudtit(strs_id, "0", 0, "");
                        if (strReturn != "0")
                        {
                            Response.Write("<script>alert('审核失败！');</script>");
                        }
                        else
                        {
                            //重新绑定数据
                            this.GetStockCheckByMain(strUserID, cls_Property.SetOrGetDataSetType);
                        }

                        //int intCounts = cls_CheckManageDAL.UpdateStockCheckState(strTm_No, strs_id, strUserID);

                        //if (intCounts == 0)
                        //{
                        //    //重新绑定数据
                        //    this.GetStockCheckByMain(strUserID, cls_Property.SetOrGetDataSetType);
                        //}
                        //else if (intCounts > 0)
                        //{
                        //    this.lblJs.Text = "<script>alert('发货数量有误，请核对后再审！');</script>";
                        //}
                        //else
                        //{
                        //    this.lblJs.Text = "<script>alert('确认失败，请重试！');</script>";
                        //}
                    }
                }

                //重新绑定结果
                this.GetStockCheckByMain(strUserID, cls_Property.SetOrGetDataSetType);
            }
            else if (intCommandName == 3)//主表取消确认
            {

                string strTm_No = ((CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("CuTextSelectBox4")).Text.Trim();
                string strs_id = ((CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbRs0")).Text.Trim();

                string strReturn = cls_CheckManageDAL.CheckWhetherAudtit(strs_id, "0", 1, "");
                if (strReturn != "0")
                {
                    Response.Write("<script>alert('取消确认失败,请重试！');</script>");
                }
                else
                {
                    //重新绑定数据
                    this.GetStockCheckByMain(strUserID, cls_Property.SetOrGetDataSetType);
                }

                //Boolean bolIsCussee = cls_CheckManageDAL.OAuditStockOrdersAffirmInto(strTm_No,strs_id);
                
                //if (bolIsCussee)
                //{
                //    //重新绑定结果
                //    this.GetStockCheckByMain(strUserID, cls_Property.SetOrGetDataSetType);
                //}
                //else
                //{
                //    this.lblJs.Text = "<script>alert('取消确认失败，请重试！')</script>";
                //}
            }
            else if (intCommandName == 1 || intCommandName == 2 || intCommandName == 4)//主表编辑
            {
                CheckBox chkRsSelect = (CheckBox)this.dgrdResult.Items[intIndex].FindControl("chkRsSelect");
                ImageButton ibtnRsCancel = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsCancel");
                ImageButton ibtnRsEdit = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsEdit");
                ImageButton ibtnRsServer = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsServer");
                ImageButton ibtnRsOAudit = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsOAudit");
                CuTextSelectBox CuTextSelectBox3 = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("CuTextSelectBox3");//实盘确认单日期
                CuTextSelectBox ctsbRs0 = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbRs0");//实盘单日期
                CuTextSelectBox ctsbRs1 = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbRsDp_id");//仓库
                CuTextSelectBox ctsbRs2 = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbRs2");//录入人
                CuTextBox ctbRs1 = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbRs1");//盘点原因

                string strTm_No = ((CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbRs0")).Text.Trim();
                if (intCommandName == 1)//取消编辑
                {
                    chkRsSelect.Visible = ibtnRsEdit.Visible = true;
                    ibtnRsCancel.Visible = ibtnRsServer.Visible = ibtnRsOAudit.Visible = false;
                    ctbRs1.ReadOnly = ctsbRs0.ReadOnly = ctsbRs1.ReadOnly = ctsbRs2.ReadOnly = true;
                }
                else if (intCommandName == 2)//编辑
                {

                    ctsbRs1.Text = ctsbRs1.ToolTip;
                    ctsbRs2.Text = ctsbRs2.ToolTip;
                    ibtnRsCancel.Visible = ibtnRsServer.Visible = true;
                    chkRsSelect.Visible = ibtnRsEdit.Visible = ibtnRsOAudit.Visible = false;
                    ctbRs1.ReadOnly = CuTextSelectBox3.ReadOnly = false;
                    
                    this.lblJs.Text = "<script>document.getElementById('txt" + ctsbRs0.ClientID + "').select();document.getElementById('" + ctsbRs0.ClientID + "_txtBox').focus();</script>";
                }
                else//保存编辑
                {
                    chkRsSelect.Visible = ibtnRsEdit.Visible = true;
                    ibtnRsCancel.Visible = ibtnRsServer.Visible = ibtnRsOAudit.Visible = false;
                    ctbRs1.ReadOnly = ctsbRs0.ReadOnly = ctsbRs1.ReadOnly = ctsbRs2.ReadOnly = true;
                    
                    //此处写保存编辑的代码
                    Boolean bolIsSucceed = cls_CheckManageDAL.UpdateCheckStock(strTm_No, DateTime.Parse(CuTextSelectBox3.Text.Trim()), ctbRs1.Text.Trim());

                    if (bolIsSucceed)
                    {
                        this.GetStockCheckByMain(strUserID, cls_Property.SetOrGetDataSetType);//重新绑定结果
                    }
                    else
                    {
                        this.lblJs.Text = "<script>alert('修改记录失败，请重试！')</script>";
                    }
                }
            }
            else//*****************************************从表相关操作****************************************
            {
                //从表修改记录的代码
                DataGrid dgrd = new DataGrid();
                string strDm_No = "";//主表单据号
                int intChildCount = this.dgrdResult.Items.Count;

                for (int i = 0; i < intChildCount; i++)
                {
                    Panel panItem = (Panel)this.dgrdResult.Items[i].FindControl("panItem");

                    if (panItem.Visible)
                    {
                        strDm_No = ((CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRs0")).Text.Trim();//主表单据号
                        dgrd = (DataGrid)this.dgrdResult.Items[i].FindControl("dgrdChildResult");
                        break;
                    }
                }

                CheckBox chkChildRsSelect = (CheckBox)dgrd.Items[intIndex].FindControl("chkChildRsSelect");
                ImageButton ibtnChildRsCancel = (ImageButton)dgrd.Items[intIndex].FindControl("ibtnChildRsCancel");
                ImageButton ibtnChildRsEdit = (ImageButton)dgrd.Items[intIndex].FindControl("ibtnChildRsEdit");
                ImageButton ibtnChildRsServer = (ImageButton)dgrd.Items[intIndex].FindControl("ibtnChildRsServer");

                TextBox ibtnBatchNo = (TextBox)dgrd.Items[intIndex].FindControl("ctbChildRsBatchNo");
                string strProductId = ((CuTextSelectBox)dgrd.Items[intIndex].FindControl("ctsbChildRs0")).Text.Trim();//商品编号
                               
                decimal dStoreQty = decimal.Parse(((CuTextBox)dgrd.Items[intIndex].FindControl("ctsbChildRsStoreQty")).Text.Trim());//仓存
                decimal dCheckQty = decimal.Parse(((TextBox)dgrd.Items[intIndex].FindControl("txtChildRsCheckQty")).Text.Trim());////盘点数量
                string strRemark = ((CuTextBox)dgrd.Items[intIndex].FindControl("ctbChildRsRemark")).Text.Trim();//备注

                CuTextSelectBox ctsbChildRs0 = (CuTextSelectBox)dgrd.Items[intIndex].FindControl("ctsbChildRs0");
                CuTextSelectBox ctsbChildRsStoreId = (CuTextSelectBox)dgrd.Items[intIndex].FindControl("ctsbChildRsStoreId");
                TextBox ctbChildRsCheckQty = (TextBox)dgrd.Items[intIndex].FindControl("txtChildRsCheckQty");
                CuTextBox ctbChildRsDiversityQty = (CuTextBox)dgrd.Items[intIndex].FindControl("ctbChildRsDiversityQty");//库存差异
                CuTextBox ctbChildRsRemark = (CuTextBox)dgrd.Items[intIndex].FindControl("ctbChildRsRemark");
                if (intCommandName == 6)//从表编辑
                {
                    this.OldBatchNo.Value = ibtnBatchNo.Text.Trim();//批号 BY SAM 2006-12-30
                    ibtnBatchNo.BorderWidth = 1;
                    chkChildRsSelect.Visible = ibtnChildRsEdit.Visible = false;
                    ibtnChildRsCancel.Visible = ibtnChildRsServer.Visible = true;
                    ctbChildRsRemark.ReadOnly = ibtnBatchNo.ReadOnly = false;
                }
                else if (intCommandName == 5)//从表取消编辑
                {
                    ibtnBatchNo.ReadOnly = true;//批号 BY SAM
                    chkChildRsSelect.Visible = ibtnChildRsEdit.Visible = true;
                    ibtnChildRsCancel.Visible = ibtnChildRsServer.Visible = false;
                    ctbChildRsCheckQty.BorderWidth = 0;
                    ctbChildRsRemark.ReadOnly = true;

                    DataSet dst = cls_CheckManageDAL.GetStockCheckChilds(strDm_No);
                    if (dst != null && dst.Tables[0].Rows.Count > 0)
                    {
                        this.BindStockCheckChildByDataView(dgrd, dst, 0);
                    }
                    
                }
                else if (intCommandName == 7)//从表保存编辑
                {
                    string strBatchNo = ibtnBatchNo.Text.Trim();//批号 BY SAM                    

                    Boolean bolIsCussee = cls_CheckManageDAL.UpDateChildCheckStock(strDm_No, strProductId, strBatchNo, dStoreQty, dCheckQty, strRemark, this.OldBatchNo.Value.Trim());
                    if (!bolIsCussee)
                    {
                        this.lblJs.Text = "<script>alert('修改实盘单明细失败，请重试！')</script>";
                    }
                    else
                    {
                        //修改后重新绑定明细表                        
                        DataSet dst = cls_CheckManageDAL.GetStockCheckChilds(strDm_No);
                        if (dst != null && dst.Tables[0].Rows.Count > 0)
                        {
                            this.BindStockCheckChildByDataView(dgrd, dst, 0);
                        }
                    }                   
                }
            }
            
        }
        else
        {
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='../index.aspx'</script>";
        }
    }

    /// <summary>
    /// 作废记录
    /// </summary>
    public void lbtnDelete_Click(object sender, EventArgs e)
    {
        int intCommandName = Int32.Parse(((LinkButton)sender).CommandName);

        this.DeleteStockCheckInfo(intCommandName);
    }

    /// <summary>
    /// 展开或收缩从表信息
    /// </summary>
    public void OpenChildResult(object sender, ImageClickEventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            ImageButton ibtnOpen = (ImageButton)sender;
            int intCommandName = Int32.Parse(ibtnOpen.CommandName);
            int intIndex = Int32.Parse(ibtnOpen.CommandArgument);
            int intCount = this.dgrdResult.Items.Count;
            bool is_audit = bool.Parse(this.dgrdResult.Items[intIndex].Cells[1].Text);

            CheckBox chkRsSelect = (CheckBox)this.dgrdResult.Items[intIndex].FindControl("chkRsSelect");
            ImageButton ibtnOpenChild = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnOpenChild");
            ImageButton ibtnRsCancel = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsCancel");
            ImageButton ibtnRsEdit = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsEdit");
            ImageButton ibtnRsServer = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsServer");
            ImageButton ibtnRsOAudit = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsOAudit");
            Panel panShowChildResult = (Panel)this.dgrdResult.Items[intIndex].FindControl("panShowChildResult");

            //获取从表信息
            CuTextBox ctbRs0 = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbRs0");
            ClsStockOrdersAffirmDAL cls_CheckManage = new ClsStockOrdersAffirmDAL();
            DataSet dst = cls_CheckManage.GetStockCheckChilds(ctbRs0.Text.Trim());

            if (dst == null || dst.Tables[0].Rows.Count <= 0)
            {
                ibtnOpen.Attributes.Add("OnClick", "return confirm('单据录入未完成，您要作废此单据吗？');");
            }

            CuTextSelectBox ctsbRsDp_id = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbRsDp_id");//仓库
            this.hidStoreId.Value = ctsbRsDp_id.ToolTip.ToString().Trim();

            if (intCommandName == 0)//展开
            {
                for (int i = 0; i < intCount; i++)
                {
                    //找到展开的项
                    Panel panItem = (Panel)this.dgrdResult.Items[i].FindControl("panItem");

                    if (i == intIndex)
                    {
                        panItem.Visible = true;
                    }
                    else
                    {
                        panItem.Visible = false;
                    }
                }

                //主表展开后则不可操作
                this.ibtnAdd.CommandName = "5";
                this.ibtnRef.CommandName = "1";
                this.ibtnDelete0.CommandName = "-1";//作废从表用（假作废）
                this.lbtnDelete0.CommandName = "-1";//作废从表用（假作废）
                this.lbtnDelete1.CommandName = "-2";//作废从表用（真作废）
                this.ibtnAdd.CommandArgument = intIndex.ToString();
                panShowChildResult.Visible = true;
                ibtnOpenChild.CommandName = "1";
                ibtnOpenChild.ImageUrl = "../App_Images/ico/10.gif";
                ibtnRsEdit.ImageUrl = "../App_Images/ico/14.gif";
                ibtnRsServer.ImageUrl = "../App_Images/ico/16.gif";
                ibtnRsOAudit.ImageUrl = "../App_Images/ico/17.gif";
                ibtnRsCancel.ImageUrl = "../App_Images/ico/18.gif";
                this.ibtnAudit.ImageUrl = "../App_Images/b_21_3.gif";
                this.ibtnAudit.Enabled = chkRsSelect.Enabled = ibtnRsCancel.Enabled = ibtnRsEdit.Enabled = ibtnRsServer.Enabled = ibtnRsOAudit.Enabled = false;
                this.lblRsCounts.Enabled = this.lblPageCounts.Enabled = this.lblCurrPage.Enabled = this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = this.lbtnNext.Enabled = this.lbtnEnd.Enabled = this.lblGoTxt1.Enabled = this.txtGo.Enabled = this.lblGoTxt2.Enabled = false;

                //如果主表确认后则从表不可操作
                if (is_audit)
                {
                    this.ibtnAdd.Enabled = this.ibtnDelete0.Enabled = false;
                    this.ibtnAdd.ImageUrl = "../App_Images/b_18_3.gif";
                    this.ibtnDelete0.ImageUrl = "../App_Images/b_19_5.gif";
                    this.imgDelete.ImageUrl = "../App_Images/b_19_6.gif";
                    this.imgDelete.Attributes.Add("OnMouseOver", "");
                    this.imgDelete.Attributes.Add("OnMouseOut", "");
                    this.imgDelete.Attributes.Add("OnClick", "");
                }

                if (dst != null && dst.Tables[0].Rows.Count > 0)
                {
                    DataGrid dgrd = (DataGrid)this.dgrdResult.Items[intIndex].FindControl("dgrdChildResult");

                    //绑定从表信息
                    this.BindStockCheckChildByDataView(dgrd, dst, 0);
                }
            }
            else//收缩
            {
                this.ibtnAdd.CommandName = "0";
                this.ibtnRef.CommandName = "0";

                if (dst != null && dst.Tables[0].Rows.Count > 0)
                {
                    //收缩后都可操作
                    this.ibtnDelete0.CommandName = "0";//恢复作废主表用
                    this.lbtnDelete0.CommandName = "0";//恢复作废主表用
                    this.lbtnDelete1.CommandName = "1";//恢复作废主表用
                    panShowChildResult.Visible = false;
                    ibtnOpenChild.CommandName = "0";
                    ibtnOpenChild.ImageUrl = "../App_Images/ico/9.gif";
                    ibtnRsEdit.ImageUrl = "../App_Images/ico/12.gif";
                    ibtnRsServer.ImageUrl = "../App_Images/ico/11.gif";
                    ibtnRsOAudit.ImageUrl = "../App_Images/ico/8.gif";
                    ibtnRsCancel.ImageUrl = "../App_Images/ico/4.gif";
                    this.ibtnAudit.ImageUrl = "../App_Images/b_21_1.gif";
                    this.ibtnAdd.ImageUrl = "../App_Images/b_18_1.gif";
                    this.ibtnDelete0.ImageUrl = "../App_Images/b_19_1.gif";
                    this.imgDelete.ImageUrl = "../App_Images/b_19_4.gif";
                    this.imgDelete.Attributes.Add("OnMouseOver", "ChangImage(this, '../App_Images/b_19_3.gif');ChangImage(document.all.ibtnDelete0, '../App_Images/b_19_2.gif')");
                    this.imgDelete.Attributes.Add("OnMouseOut", "ChangImage(this, '../App_Images/b_19_4.gif');ChangImage(document.all.ibtnDelete0, '../App_Images/b_19_1.gif')");
                    this.imgDelete.Attributes.Add("OnClick", "ChildMenuVisible()");
                    this.ibtnAdd.Enabled = this.ibtnDelete0.Enabled = this.ibtnAudit.Enabled = chkRsSelect.Enabled = ibtnRsCancel.Enabled = ibtnRsEdit.Enabled = ibtnRsServer.Enabled = ibtnRsOAudit.Enabled = true;

                    //重新绑定
                    DataSet dstM = cls_Property.SetOrGetCorporationDataSet;
                    this.BindStockCheckByDataView(dstM, this.dgrdResult.CurrentPageIndex);
                }
                else
                {
                    Boolean is_Succeed = cls_CheckManage.DeleteCheckStock(ctbRs0.Text.Trim(), 1);
                }

                this.GetStockCheckByMain(strUserID, cls_Property.SetOrGetDataSetType);//重新绑定数据
            }
        }
        else
        {
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='../index.aspx'</script>";
        }
    } 

    /// <summary>
    /// 获取所有主表记录
    /// </summary>
    private void GetStockCheckByMain(string UserID, int Type)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        cls_Property.SetOrGetDataSetType = Type;

        ClsStockOrdersAffirmDAL cls_CheckManage = new ClsStockOrdersAffirmDAL();

        DataSet dst = cls_CheckManage.GetOrderInformationByStatu(UserID, Type);

        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            cls_Property.SetOrGetCorporationDataSet = dst;

            this.BindStockCheckByDataView(dst, 0);
        }
        else
        {
            this.dgrdResult.CurrentPageIndex = 0;
            this.dgrdResult.DataSource = null;
            this.dgrdResult.DataBind();
            this.lblRsCounts.Text = "共0条记录";
            this.lblPageCounts.Text = "共0页";
            this.lblCurrPage.Text = "当前第0页";
            this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = this.lbtnNext.Enabled = this.lbtnEnd.Enabled = this.txtGo.Enabled = false;
            this.lblRsCounts.Enabled = this.lblPageCounts.Enabled = this.lblCurrPage.Enabled = this.lblGoTxt1.Enabled = this.lblGoTxt2.Enabled = false;
        }
    }

    /// <summary>
    /// 绑定主表信息到数据控件
    /// </summary>
    private void BindStockCheckByDataView(DataSet dst, int CurrPageIndex)
    {
        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            this.dgrdResult.CurrentPageIndex = CurrPageIndex;
            this.dgrdResult.DataSource = dst;
            this.dgrdResult.DataBind();

            this.lblRsCounts.Text = "共" + dst.Tables[0].Rows.Count + "条记录";
            this.lblPageCounts.Text = "共" + this.dgrdResult.PageCount + "页";
            this.lblCurrPage.Text = "当前第" + (this.dgrdResult.CurrentPageIndex + 1) + "页";
            this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = this.lbtnNext.Enabled = this.lbtnEnd.Enabled = this.txtGo.Enabled = true;
            this.lblRsCounts.Enabled = this.lblPageCounts.Enabled = this.lblCurrPage.Enabled = this.lblGoTxt1.Enabled = this.lblGoTxt2.Enabled = true;

            if (this.dgrdResult.PageCount == 1)
            {
                this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = this.lbtnNext.Enabled = this.lbtnEnd.Enabled = false;
                this.lblGoTxt1.Enabled = this.txtGo.Enabled = this.lblGoTxt2.Enabled = false;
            }
            else if (this.dgrdResult.CurrentPageIndex == this.dgrdResult.PageCount - 1)
            {
                this.lbtnNext.Enabled = this.lbtnEnd.Enabled = false;
            }
            else if (this.dgrdResult.CurrentPageIndex == 0)
            {
                this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = false;
            }
        }
    }

    /// <summary>
    /// 绑定从表信息到数据控件
    /// </summary>
    private void BindStockCheckChildByDataView(DataGrid dgrd, DataSet dst, int CurrPageIndex)
    {
        if (dgrd != null && dst != null)
        {
            dgrd.CurrentPageIndex = CurrPageIndex;
            dgrd.DataSource = dst;
            dgrd.DataBind();

            int intIndex = Int32.Parse(dgrd.ToolTip);
            int intItems = dgrd.Items.Count;

            Label lblChildRsCounts = (Label)this.dgrdResult.Items[intIndex].FindControl("lblChildRsCounts");
            Label lblChildPageCounts = (Label)this.dgrdResult.Items[intIndex].FindControl("lblChildPageCounts");
            Label lblChildCurrPage = (Label)this.dgrdResult.Items[intIndex].FindControl("lblChildCurrPage");
            LinkButton lbtnChildFirst = (LinkButton)this.dgrdResult.Items[intIndex].FindControl("lbtnChildFirst");
            LinkButton lbtnChildPrev = (LinkButton)this.dgrdResult.Items[intIndex].FindControl("lbtnChildPrev");
            LinkButton lbtnChildNext = (LinkButton)this.dgrdResult.Items[intIndex].FindControl("lbtnChildNext");
            LinkButton lbtnChildEnd = (LinkButton)this.dgrdResult.Items[intIndex].FindControl("lbtnChildEnd");

            lblChildRsCounts.Text = "共" + dst.Tables[0].Rows.Count + "条明细记录";
            lblChildPageCounts.Text = "共" + dgrd.PageCount + "页";
            lblChildCurrPage.Text = "当前第" + (dgrd.CurrentPageIndex + 1) + "页";
            lbtnChildFirst.Enabled = lbtnChildPrev.Enabled = lbtnChildNext.Enabled = lbtnChildEnd.Enabled = true;
            lblChildRsCounts.Enabled = lblChildPageCounts.Enabled = lblChildCurrPage.Enabled = true;

            if (dgrd.PageCount == 1)
            {
                lbtnChildFirst.Enabled = lbtnChildPrev.Enabled = lbtnChildNext.Enabled = lbtnChildEnd.Enabled = false;
            }
            else if (dgrd.CurrentPageIndex == dgrd.PageCount - 1)
            {
                lbtnChildNext.Enabled = lbtnChildEnd.Enabled = false;
            }
            else if (dgrd.CurrentPageIndex == 0)
            {
                lbtnChildFirst.Enabled = lbtnChildPrev.Enabled = false;
            }

            //判断从表中的记录是否可操作
            for (int i = 0; i < intItems; i++)
            {
                CheckBox chkChildRsSelect = (CheckBox)dgrd.Items[i].FindControl("chkChildRsSelect");
                ImageButton ibtnChildRsEdit = (ImageButton)dgrd.Items[i].FindControl("ibtnChildRsEdit");

                if (!this.ibtnAdd.Enabled)
                {
                    chkChildRsSelect.Enabled = ibtnChildRsEdit.Enabled = false;
                    ibtnChildRsEdit.ImageUrl = "../App_Images/ico/14.gif";
                }
                else
                {
                    chkChildRsSelect.Enabled = ibtnChildRsEdit.Enabled = true;
                    ibtnChildRsEdit.ImageUrl = "../App_Images/ico/12.gif";
                }
            }

            //保存从表中的结果集和DataGrid控件用于从表中的翻页
            ClsPropertyDAL cls_Property = new ClsPropertyDAL();
            cls_Property.SetOrGetChildResultDataSet = dst;
            cls_Property.SetOrGetChildDataGridControl = dgrd;
        }
    }

    /// <summary>
    /// 作废记录
    /// </summary>
    private void DeleteStockCheckInfo(int CommandName)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            int intCommand = Int32.Parse(this.ibtnRef.CommandName);
            int intCount = this.dgrdResult.Items.Count;

            ClsStockOrdersAffirmDAL cls_CheckManageDAL = new ClsStockOrdersAffirmDAL();
            if (intCommand == 0)//作废主表记录
            {
                for (int i = 0; i < intCount; i++)
                {
                    CheckBox chkBox = (CheckBox)this.dgrdResult.Items[i].FindControl("chkRsSelect");

                    if (chkBox.Checked)
                    {
                        bool is_audit = bool.Parse(this.dgrdResult.Items[i].Cells[1].Text.Trim());

                        if (!is_audit)
                        {
                            CuTextBox txtBox = (CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRs0");

                            Boolean bolIsCussee = cls_CheckManageDAL.DeleteCheckStock(txtBox.Text.Trim(), CommandName);

                            if (!bolIsCussee)
                            {
                                this.lblJs.Text = "<script>alert('作废实盘确认单信息失败，请重试！')</script>";
                            }
                        }
                        else
                        {
                            this.lblJs.Text = "<script>alert('此单已确认，不能作废！')</script>";
                        }
                    }
                }
                //重新绑定主表结果
                this.GetStockCheckByMain(strUserID, cls_Property.SetOrGetDataSetType);
            }
            else if (CommandName == -1 || CommandName == -2)//作废从表:-1假作废,-2真作废
            {
                DataGrid dgrd = new DataGrid();
                string strDm_No = "";//主表单据号
                int intChildCount = this.dgrdResult.Items.Count;

                for (int i = 0; i < intChildCount; i++)
                {
                    Panel panItem = (Panel)this.dgrdResult.Items[i].FindControl("panItem");

                    if (panItem.Visible)
                    {
                        strDm_No = ((CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRs0")).Text.Trim();
                        dgrd = (DataGrid)this.dgrdResult.Items[i].FindControl("dgrdChildResult");
                        break;
                    }
                }

                int intChildItem = dgrd.Items.Count;

                for (int j = 0; j < intChildItem; j++)
                {
                    CheckBox checkBox = (CheckBox)dgrd.Items[j].FindControl("chkChildRsSelect");

                    if (checkBox.Checked)
                    {
                        string strChildIm_No = ((CuTextSelectBox)dgrd.Items[j].FindControl("ctsbChildRs0")).Text.Trim();//明细产品编号
                        string strChildBatchNo = ((CuTextBox)dgrd.Items[j].FindControl("ctbChildRsBatchNo")).Text.Trim();//明细产品批号

                        Boolean bolIsCussee = cls_CheckManageDAL.DeleteChildCheckStock(strDm_No, strChildIm_No, strChildBatchNo, CommandName);

                        if (!bolIsCussee)
                        {
                            this.lblJs.Text = "<script>alert('作废实盘单明细失败，请重试！')</script>";
                        }
                    }
                }

                DataSet dst = cls_CheckManageDAL.GetStockCheckChilds(strDm_No);

                if (dst != null && dst.Tables[0].Rows.Count > 0)
                {
                    this.BindStockCheckChildByDataView(dgrd, dst, 0);
                }
                else
                {
                    dgrd.DataSource = null;
                    dgrd.DataBind();
                }
            }
        }
        else
        {
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='../index.aspx'</script>";
        }
    }

    private void ControlButtonVisible(string UserLogID, string CurrPageID)
    {
        ClsMenuDAL cls_Menu = new ClsMenuDAL();
        DataSet dst = cls_Menu.GetCurrUserButtonPopedom(UserLogID, CurrPageID);

        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            int intCount = dst.Tables[0].Rows.Count - 1;

            for (int i = intCount; i >= 0; i--)
            {
                int intButtonID = Int32.Parse(dst.Tables[0].Rows[i][2].ToString());

                switch (intButtonID)
                {
                    case 0:
                        this.panAdd.Visible = true;
                        break;
                    case 1:
                        this.hidButtonEdit.Value = intButtonID.ToString();
                        break;
                    case 2:
                        this.panDelete.Visible = true;
                        break;
                    case 3:
                        this.lbtnDelete1.Enabled = true;
                        break;
                    case 4:
                        this.panAudit.Visible = true;
                        break;
                    case 5:
                        this.hidButtonOAudit.Value = intButtonID.ToString();
                        break;
                    case 6:
                        this.panRef.Visible = true;
                        break;
                    case 7:
                        this.panSearch.Visible = true;
                        break;
                    case 8:
                        break;
                    case 9:
                        this.panQuery.Visible = true;
                        break;
                    case 10:
                        this.lbtnNotAudit.Enabled = true;
                        break;
                    case 11:
                        this.lbtnAuditing.Enabled = true;
                        break;
                    case 12:
                        this.lbtnEndAudit.Enabled = true;
                        break;
                    case 13:
                        break;
                    case 14:
                        break;
                    case 15:
                        this.lbtnNotCnacel.Enabled = true;
                        break;
                    case 16:
                        this.lbtnEndCnacel.Enabled = true;
                        break;
                    case 17:
                        break;
                    case 18:
                        break;
                    case 19:
                        this.lbtnAll.Enabled = true;
                        break;
                }
            }
        }
    }   

    /// <summary>
    /// 作废记录事件
    /// </summary>
    protected void ibtnDelete0_Click(object sender, ImageClickEventArgs e)
    {
        int intCommandName = Int32.Parse(((ImageButton)sender).CommandName);

        this.DeleteStockCheckInfo(intCommandName);
    }

    /// <summary>
    /// 记录页面跳转
    /// </summary>
    protected void txtGo_TextChanged(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        DataSet dst = cls_Property.SetOrGetCorporationDataSet;

        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            string strIndex = this.txtGo.Text.Trim();
            this.txtGo.Text = String.Empty;

            if (strIndex != "")
            {
                try
                {
                    int intIndex = Int32.Parse(strIndex) - 1;

                    if (intIndex >= 0 && intIndex < this.dgrdResult.PageCount)
                    {
                        this.BindStockCheckByDataView(dst, intIndex);
                    }
                    else
                    {
                        this.lblJs.Text = "<script>alert('请输入正确的页码数！')</script>";
                    }
                }
                catch
                {
                    this.lblJs.Text = "<script>alert('请输入数字类型的页码！')</script>";
                }
            }
            else
            {
                this.lblJs.Text = "<script>alert('请输入要跳转的页码！')</script>";
            }
        }
    }

    /// <summary>
    /// 主表或从表刷新
    /// </summary>
    protected void ibtnRef_Click(object sender, ImageClickEventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            int intCommand = Int32.Parse(((ImageButton)sender).CommandName);

            if (intCommand == 0)//刷新主表
            {
                this.GetStockCheckByMain(strUserID, cls_Property.SetOrGetDataSetType);
            }
            else//刷新从表
            {

            }
        }
        else
        {
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='../index.aspx'</script>";
        }
    }

    /// <summary>
    /// 数据控件绑定数据项后被触发的事件
    /// </summary>
    protected void dgrdResult_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemIndex != -1)
        {
            bool Is_audit = bool.Parse(e.Item.Cells[1].Text.Trim());

            CheckBox chkRsSelect = (CheckBox)e.Item.FindControl("chkRsSelect");
            CuTextBox ctbRs1 = (CuTextBox)e.Item.FindControl("ctbRs1");
            ImageButton ibtnRsEdit = (ImageButton)e.Item.FindControl("ibtnRsEdit");
            ImageButton ibtnRsCancel = (ImageButton)e.Item.FindControl("ibtnRsCancel");
            ImageButton ibtnRsServer = (ImageButton)e.Item.FindControl("ibtnRsServer");
            ImageButton ibtnRsOAudit = (ImageButton)e.Item.FindControl("ibtnRsOAudit");

            //修改按回车提交
            if (ctbRs1.ReadOnly)
            {
                ctbRs1.Attributes.Add("onkeydown", "if(event.keyCode == 13){document.getElementById('" + ibtnRsServer.ClientID + "').click();}");
            }

            string strButtonEdit = this.hidButtonEdit.Value;
            string strButtonOAudit = this.hidButtonOAudit.Value;

            if (!Is_audit)
            {
                if (strButtonEdit.Trim() == "1")
                {
                    if (this.panAudit.Visible || this.panDelete.Visible)
                    {
                        chkRsSelect.Visible = true;
                    }

                    ibtnRsEdit.Visible = true;
                }
                else if (this.panAudit.Visible || this.panDelete.Visible)
                {
                    chkRsSelect.Visible = true;
                }

                //chkRsSelect.Visible = ibtnRsEdit.Visible = true;
                //ibtnRsOAudit.Visible = ibtnRsCancel.Visible = ibtnRsServer.Visible = false;
            }
            else
            {
                ibtnRsOAudit.Visible = true;

                if (strButtonOAudit.Trim() != "5")
                {
                    ibtnRsOAudit.Enabled = false;
                    ibtnRsOAudit.ImageUrl = "../App_Images/ico/17.gif";
                }

                //ibtnRsOAudit.Visible = true;
                //chkRsSelect.Visible = ibtnRsEdit.Visible = ibtnRsCancel.Visible = ibtnRsServer.Visible = false;
            }
        }
    }

    /// <summary>
    /// 根据订单状态进行相关查询
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public void lbtnQuery_Click(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            int intCommandName = Int32.Parse(((LinkButton)sender).CommandName);

            this.GetStockCheckByMain(strUserID, intCommandName);
        }
        else
        {
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='../index.aspx'</script>";
        }
    }

    protected void ImgbtnNotAudit_Click(object sender, ImageClickEventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            int intCommandName = Int32.Parse(((ImageButton)sender).CommandName);

            this.GetStockCheckByMain(strUserID, intCommandName);
        }
        else
        {
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='../index.aspx'</script>";
        }
    }
}
